<template>
  <el-form style="width: 60%" :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
    <el-form-item label="教师号">
      <el-input v-model="ruleForm.Tno" readonly></el-input>
    </el-form-item>

    <el-form-item label="教师名" prop="Tname">
      <el-input v-model="ruleForm.Tname"></el-input>
    </el-form-item>

    <el-form-item label="教师等级" prop="Trank">
      <el-input v-model="ruleForm.Trank"></el-input>
    </el-form-item>

    <el-form-item label="教师特长" prop="Tspeciality">
      <el-input v-model="ruleForm.Tspeciality"></el-input>
    </el-form-item>
    <el-form-item>
      <el-button type="primary" @click="submitForm('ruleForm')">修改</el-button>
      <el-button @click="resetForm('ruleForm')">重置</el-button>
    </el-form-item>
  </el-form>
</template>
<script>
export default {
  created() {
    const _this=this;
    this.axios.post('http://localhost:8152/api/auth/teacher/find-tno',this.$route.query).then((res)=> {
      console.log(res.data)
      _this.ruleForm = res.data
    })
  },
  data() {
    return {
      ruleForm: {
        Tno: '',
        Tname: '',
        Trank:'',
        Tspeciality:''
      },
      rules: {
        Tname: [
          { required: true, message: '教师名不能为空', trigger: 'blur' }
        ],
        Trank: [
          { required: true, message: '教师等级为空', trigger: 'blur' }
        ],
        Tspecialty: [
          { required: true, message: '教师特长为空', trigger: 'blur' }
        ],
      }
    };
  },
  methods: {
    submitForm(formName) {
      const _this = this;
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.axios.post('http://localhost:8152/api/auth/teacher/update',{...this.ruleForm}).then((res) =>{
            if(res.data.msg == '修改成功'){
              _this.$alert(this.ruleForm.Tname+'修改成功！', '消息', {
                confirmButtonText: '确定',
                callback: action => {
                  _this.$router.push('/teacherInformation')
                }
              })
            }
          })
        } else {
          return false;
        }
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    }
  },
}
</script>
